package proto

import (
    "cli-desktop/public"
    "net"
)

/*
*  -*- coding:utf8 -*-
*
*
*
*  @Author  : chengms
*  @WebSite : chengms.com
*  @Email   : chengms2012@163.com
*  @TIME    : 2020/8/25 10:26
*  @File    : ConnSvc.go
 */

type ConnServer struct {
    SvcConn   net.Conn
    Writer    *CommandWriter
    Reader    *CommandReader
}

var ConnSvc ConnServer

func (c *ConnServer)ConnectServer(addr string) error {
    var err error
    c.SvcConn, err = net.Dial("tcp", addr)
    if err != nil {
        return err
    }
    public.Loggerf.Info("Connect to Addr: ", addr)

    c.Writer = NewCommandWriter(c.SvcConn)
    c.Reader = NewCommandReader(c.SvcConn)

    return nil
}

func (c *ConnServer)SendMsg(msg interface{}) error {
    err := c.Writer.Write(msg)
    return err
}



